package com.chinasofti.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Predicate;

public class Demo01 {
    public static void main(String[] args) {
        //method1();
        // method2();
        //method3();
        Collection<String> c = new ArrayList<>();
        //添加元素
        c.add("aaaaa");
        c.add("bbb");
        c.add("ccc");
        c.add("dddee");
        //删除长度为3的元素
//        c.removeIf(new Predicate(){
//            @Override
//            public boolean test(Object o) {
//                return ((String)o).length() == 3;
//            }
//        });
        //c.removeIf((String s)->{return s.length() == 3;});
        c.removeIf((String s)->s.length() == 3);
        System.out.println(c);

    }

    private static void method3() {
        Collection<String> c = new ArrayList<>();
        //添加元素
        c.add("aaa");
        c.add("bbb");
        c.add("ccc");
        c.add("ddd");
        boolean b = c.remove("aaa");
        boolean d = c.remove("a");
        System.out.println("d = " + d);
        System.out.println("b = " + b);
        System.out.println(c);
    }

    private static void method2() {
        Collection<String> c = new ArrayList<>();
        //添加元素
        c.add("aaa");
        c.add("bbb");
        c.add("ccc");
        c.add("ddd");
        //判断集合中是否包含指定元素
        boolean b = c.contains("a");
        boolean b1 = c.contains("aaa");
        System.out.println("b1 = " + b1);
        System.out.println("b = " + b);
    }

    private static void method1() {
        Collection<String> c = new ArrayList<>();
        //添加元素
        c.add("aaa");
        c.add("bbb");
        c.add("ccc");
        c.add("ddd");

        int size = c.size();
        System.out.println("size = " + size);

        boolean b = c.isEmpty();//集合是否为空
        System.out.println("b1 = " + b);

        c.clear();//清空集合

        b = c.isEmpty();//集合是否为空
        System.out.println("b2 = " + b);
    }
}
